<script type="text/javascript">
    $(document).ready(function() {
        $('.jqzoom').jqzoom({
            zoomType: 'standard',
            lens:true,
            preloadImages: true,
            alwaysOn:false,
            zoomWidth: 300,
            zoomHeight: 300,
            preloadText: 'Loading……'
        });
    });
</script>
<div class="span15">
    <div style="font-size: 23px; font-weight: bold; color: #333;">
        <?php echo $this->escapeHtml($this->goodsInfo[0]->getGoodsName()); ?> <span style="color: #ed145b;"><?php echo $this->escapeHtml($this->goodsInfo[0]->getGoodsExtendName()); ?></span>
    </div>
    <div class="span8 J_mi_goodsPic_block">
        <div id="J_mi_goodsPicBox" class="goods-pic-box">
            <?php
            if(($this->goodsImages && count($this->goodsImages) > 1) || ($this->specImages && count($this->specImages) > 1)) {
                if($this->specImages) echo $this->partial('shop/goods/goods-spec-image-slide', ['specImages' => $this->specImages, 'goodsInfo' => $this->goodsInfo]);
                else echo $this->partial('shop/goods/goods-image-slide', ['goodsImages' => $this->goodsImages, 'goodsInfo' => $this->goodsInfo]);
            } else {
                ?>
                <div style="margin: 20px 0 10px; width: 430px;height: 410px;">
                    <?php if ($this->specImages) { ?>
                        <a rel='gal1' href="<?php echo $this->shopHelper()->baseGoodsImagePath($this->specImages[0]['goodsImage']); ?>" title="<?php echo $this->escapeHtml($this->goodsInfo[0]->getGoodsName()); ?>" class="jqzoom"><img class="goods-big-pic" src="<?php echo $this->shopHelper()->baseGoodsImagePath($this->specImages[0]['goodsThumbnailImage']); ?>"></a>
                    <?php } else { ?>
                        <a rel='gal1' href="<?php echo $this->shopHelper()->baseGoodsImagePath($this->goodsInfo['goodsImage']); ?>" title="<?php echo $this->escapeHtml($this->goodsInfo[0]->getGoodsName()); ?>" class="jqzoom"><img class="goods-big-pic" src="<?php echo $this->shopHelper()->baseGoodsImagePath($this->goodsInfo['goodsThumbnailImage']); ?>"></a>
                    <?php } ?>
                </div>
            <?php } ?>
        </div>
    </div>

    <?php
    $goodsMarketPrice = $this->goodsInfo[0]->getGoodsMarketPrice() > 0 ? '&nbsp;&nbsp;<del style="color: #aaa">'.$this->frontCurrency($this->goodsInfo[0]->getGoodsMarketPrice()).'</del>' : '';

    $userGroupPriceShowState = $this->shopHelper()->shop('goods_group_price_show', 'goods', 'config');
    $goodsPriceStr = '';
    if ($this->goodsInfo['discountPrice'] <= 0) {
        $userGroupPrice = $this->specGoodsInfo ? array_filter(unserialize($this->specGoodsInfo->getSpecGoodsUserGroupPrice())) : array_filter(unserialize($this->goodsInfo[0]->getGoodsUserGroupPrice()));

        if(!empty($userGroupPrice) && $this->shopHelper()->checkUserLoginStatus() && isset($userGroupPrice[$this->shopHelper()->getUserLoginData('user_group_id')]) && $userGroupPrice[$this->shopHelper()->getUserLoginData('user_group_id')] > 0) {
            $shopGoodsPrice = $userGroupPrice[$this->shopHelper()->getUserLoginData('user_group_id')];
        } else {
            $shopGoodsPrice = $this->specGoodsInfo ? $this->specGoodsInfo->getSpecGoodsPrice() : $this->goodsInfo[0]->getGoodsPrice();
        }
        $goodsPriceStr .= '<dd><strong>'.$this->translate('价　格').'：</strong><span style="color: #ED145B;font-size: 20px;font-weight:bold;" id="goods_price">'. $this->frontCurrency($shopGoodsPrice) . '</span>'.$goodsMarketPrice.'</dd>';
        if($userGroupPriceShowState == 1 && !empty($userGroupPrice)) {
            $goodsPriceStr .= '<dd class="group_price"><strong>'.$this->translate('会员价').'：</strong><span class="group_price" id="group_price_str">';
            foreach ($userGroupPrice as $groupPriceKey => $groupPriceValue) {
                if($groupPriceValue > 0) $goodsPriceStr .= $this->escapeHtml($this->userGroup[$groupPriceKey]) . '<strong style="color:#ED145B;">'.$this->frontCurrency($groupPriceValue).'</strong>&nbsp;&nbsp;';
            }
            $goodsPriceStr .= '</span></dd>';
        }
    } else {
        $shopGoodsPrice = $this->goodsInfo['discountPrice'];
        $goodsPriceStr .= '<dd><strong>'.$this->translate('优惠价').'：</strong><span style="color: #ED145B;font-size: 20px;font-weight:bold;" id="goods_price">'.$this->frontCurrency($shopGoodsPrice).'</span>'.$goodsMarketPrice.'</dd>';
    } ?>

    <!-- 跟随 导航 -->
    <div class="goods-sub-bar" id="goodsSubBar">
        <div class="container">
            <div class="row">
                <div class="span5">
                    <dl class="goods-sub-bar-info clearfix">
                        <dt><img src="<?php echo $this->shopHelper()->baseGoodsImagePath($this->goodsInfo['goodsThumbnailImage']); ?>"></dt>
                        <dd>
                            <strong><?php echo $this->escapeHtml($this->goodsInfo[0]->getGoodsName()); ?></strong>
                            <p>
                                <em><span class="J_mi_goodsPrice"><?php echo $this->frontCurrency($shopGoodsPrice); ?></span></em>
                            </p>
                        </dd>
                    </dl>
                </div>
                <div class="span15">
                    <div class="fr" id="goodsSubBarBtnBox">
                        <a href="javascript:;"  onclick="goodsAddCart();" class="btn btn-primary goods-add-cart-btn">
                            <i class="iconfont">&#xe624;</i><?php echo $this->translate('加入购物车'); ?>
                        </a>
                    </div>
                    <div class="goods-desc-menu" id="goodsSubMenu">
                        <ul class="items clearfix J_pro_related_btns">
                            <li class="current">
                                <a href="#goodsDesc"><?php echo $this->translate('详细信息'); ?></a>
                            </li>
                            <li>
                                <a href="#goodsComment"><?php echo $this->translate('商品评价'); ?></a>
                            </li>
                            <?php if($this->shopHelper()->shop('goods_consultation_state', 'goods') == 1) { ?>
                                <li>
                                    <a href="#goodsFaq"><?php echo $this->translate('商品咨询'); ?></a>
                                </li>
                            <?php } ?>
                            <li>
                                <a href="#serQue"><?php echo $this->translate('售后服务'); ?></a>
                            </li>
                            <li>
                                <a href="#goodsBuyQue"><?php echo $this->translate('如何购买'); ?></a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="span7">
        <div style="height: 32px;line-height: 32px;margin-right: 5px;padding: 0 10px;overflow: hidden;zoom: 1;background-color: #e4393c;">
            <div style="float: left;">
                <strong style="color: #ffe134;"><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo $this->translate('预售'); ?></strong>
            </div>
            <?php if (isset($this->showData['presaleGoods']['presaleGoodsStartTime'])) { ?>
            <div style="float: right">
                <span style="display: inline;">
                    <span style="color: white;">
                        <i class="fa fa-history" aria-hidden="true"></i>
                        <?php
                        $newTime = time();
                        if ($this->showData['presaleGoods']['presaleGoodsStartTime'] > $newTime) echo $this->translate('预售时间');
                        if ($newTime >= $this->showData['presaleGoods']['presaleGoodsStartTime'] && $newTime <= $this->showData['presaleGoods']['presaleGoodsEndTime']) echo $this->translate('预售剩余');
                        if ($newTime > $this->showData['presaleGoods']['presaleGoodsEndTime']) echo $this->translate('预售结束');
                        ?>
                    </span>
                    <em style="color: #ffe134;">
                        <?php if ($this->showData['presaleGoods']['presaleGoodsStartTime'] > $newTime) echo $this->showData['presaleGoods']['presaleGoodsStartTimeStr']; ?>
                        <?php if ($newTime >= $this->showData['presaleGoods']['presaleGoodsStartTime'] && $newTime <= $this->showData['presaleGoods']['presaleGoodsEndTime']) { ?>
                            <span id="end-time"></span>
                            <script>
                                var presaleSeconds = <?php echo $this->showData['presaleGoods']['presaleGoodsEndTime'] - time(); ?>;
                                function countDownTime() {
                                    if (presaleSeconds <= 0) {
                                        $('#end-time').html('<?php echo $this->translate('预售结束'); ?>');
                                        clearInterval(countDownTime);
                                    } else {
                                        let d = Math.floor(presaleSeconds / (24 * 3600));
                                        let h = Math.floor((presaleSeconds - 24 * 3600 * d) / 3600);
                                        let m = Math.floor((presaleSeconds - 24 * 3600 * d - h * 3600) / 60);
                                        let s = Math.floor((presaleSeconds - 24 * 3600 * d - h * 3600 - m * 60));
                                        $('#end-time').html(d+'<?php echo $this->translate('天'); ?>'+h+'<?php echo $this->translate('小时'); ?>'+m+'<?php echo $this->translate('分'); ?>'+s+'<?php echo $this->translate('秒'); ?>');
                                        presaleSeconds = presaleSeconds - 1;
                                    }
                                }
                                setInterval(countDownTime, 1000)
                            </script>
                        <?php } ?>
                    </em>
                </span>
            </div>
            <?php } ?>
        </div>
        <dl class="goods-info-box">
            <dt class="goods-info-head" id="spec">
                <dl>
                    <dd>
                        <strong><?php echo $this->translate('货　号'); ?>：</strong><span id="goods_item"><?php echo $this->specGoodsInfo ? $this->escapeHtml($this->specGoodsInfo->getSpecGoodsItem()) : $this->escapeHtml($this->goodsInfo[0]->getGoodsItem()); ?></span>
                    </dd>
                    <?php echo $goodsPriceStr; ?>
                    <dd>
                        <strong><?php echo $this->translate('定　金'); ?>：</strong><span style="color: #ED145B;font-size: 20px;font-weight: bold;"><?php echo $this->escapeHtml($this->showData['presaleGoods']['presalePrice']); ?></span> <?php if (isset($this->showData['presaleGoods']['presaleExtendPrice'])) { ?><em style="color:#fff;background: #E5004F;padding: 5px 5px;"><?php echo $this->translate('尾款立减') . ' ' . $this->showData['presaleGoods']['presaleExtendPrice']; ?></em><?php } ?>
                    </dd>
                    <?php if (!empty($this->goodsInfo['brandName'])) { ?>
                        <dd>
                            <strong><?php echo $this->translate('品　牌'); ?>：</strong><a href="<?php echo $this->url('shop-brand', ['action'=>'brandGoodsList', 'id' => $this->goodsInfo[0]->getBrandId()]); ?>"><?php echo $this->escapeHtml($this->goodsInfo['brandName']); ?></a>
                        </dd>
                    <?php } ?>
                    <?php
                    if ($this->goodsCustom) {
                        foreach($this->goodsCustom as $customValue) {
                            ?>
                            <dd>
                                <strong><?php echo $this->escapeHtml($customValue->getCustomTitle()); ?>：</strong>
                                <?php echo $this->escapeHtml($customValue->getCustomContent()); ?>
                            </dd>
                        <?php } } ?>
                    <dd>
                        <strong><?php echo $this->translate('库　存'); ?>：</strong><span id="goods_stock_show"><?php echo $this->goodsInfo['stockShowState'] == 1 ? $this->shopHelper()->goodsStockShow($this->goodsInfo['stockShow']) : ($this->specGoodsInfo ? ($this->specGoodsInfo->getSpecGoodsStock() <= $this->goodsInfo['stockOutSetNum'] ? $this->shopHelper()->goodsOutStockShow($this->goodsInfo['stockOutShow']) : ($this->goodsInfo['stockShowState'] == 2 ? $this->shopHelper()->goodsStockShow($this->goodsInfo['stockShow']) : $this->specGoodsInfo->getSpecGoodsStock())) : ($this->goodsInfo['stockNum'] <= $this->goodsInfo['stockOutSetNum'] ? $this->shopHelper()->goodsOutStockShow($this->goodsInfo['stockOutShow']) : ($this->goodsInfo['stockShowState'] == 2 ? $this->shopHelper()->goodsStockShow($this->goodsInfo['stockShow']) : $this->goodsInfo['stockNum']))); ?></span>
                    </dd>
                    <?php
                    $goodsWeight = $this->specGoodsInfo ? $this->specGoodsInfo->getSpecGoodsWeight() : $this->goodsInfo[0]->getGoodsWeight();
                    if($goodsWeight > 0) { ?>
                        <dd>
                            <strong><?php echo $this->translate('重　量'); ?>：</strong><?php echo $goodsWeight . $this->goodsInfo[0]->getGoodsWeightUnit(); ?>
                        </dd>
                    <?php } ?>
                    <?php if (isset($this->showData['strArray']) && !empty($this->showData['strArray'])) foreach ($this->showData['strArray'] as $strValue) { ?>
                        <dd>
                            <strong><?php echo $this->escapeHtml($strValue['name']); ?>：</strong><?php echo $this->escapeHtml($strValue['value']); ?>
                        </dd>
                    <?php } ?>
                    <?php if (isset($this->showData['discountArray']) && !empty($this->showData['discountArray'])) { ?>
                        <dd style="margin-top: 5px;margin-bottom: 5px;">
                            <strong style="float: left;"><?php echo $this->translate('活　动'); ?>：</strong>
                            <div style="margin-left: 60px;">
                                <?php foreach ($this->showData['discountArray'] as $discountValue) { ?>
                                    <p style="margin-bottom: 3px;"><em class="goods-info-discount"><?php echo $this->escapeHtml($discountValue['tag']); ?></em> <?php echo $this->escapeHtml($discountValue['title']); ?></p>
                                <?php } ?>
                            </div>
                        </dd>
                    <?php } ?>
                    <?php if (isset($this->showData['couponArray']) && !empty($this->showData['couponArray'])) { ?>
                        <dd>
                            <strong><?php echo $this->translate('优惠券'); ?>：</strong>
                            <?php foreach ($this->showData['couponArray'] as $couponKey => $couponValue) { if ($couponKey == 3) break; ?>
                                <div style="min-width: 50px;height: 26px;background:#E5004F;line-height:26px;color: #fff;display: inline-block;text-align: center;">
                                    &nbsp;<?php echo $this->translate('满').$this->frontCurrency($couponValue['shoppingAmount']).$this->translate('减').$this->frontCurrency($couponValue['shoppingDiscount']); ?> &nbsp;&nbsp;
                                </div>
                                <div style="width: 10px;height: 10px;border-radius: 50%;background: #fff;display: inline-block;margin-left: -10px;position: relative;">
                                </div>
                            <?php } ?>
                            <span>
                                        <a style="text-decoration: underline;" href="<?php echo $this->url('shop-goods', ['action' => 'clickGoodsCoupon', 'id' => $this->goodsInfo[0]->getGoodsId()]); ?>" target="_blank"><?php echo $this->translate('点击领券'); ?></a>
                                    </span>
                        </dd>
                    <?php } ?>

                    <?php if($this->goodsInfo[0]->getGoodsIntegralBuy() == 1) { ?>
                        <dd style="margin-top:8px;font-size: 14px;"><strong><?php echo $this->translate('可积分兑换'); ?>：<?php echo $this->shopHelper()->getGoodsIntegral($shopGoodsPrice); ?></strong></dd>
                    <?php } ?>

                    <?php if($this->goodsInfo[0]->getWholesaleState() == 1 && $this->goodsWholesaleList) { ?>
                        <div class="clearfix" style="margin-bottom: 10px;margin-top: 10px;">
                            <div>
                                <strong><?php echo $this->translate('批发售价');?></strong>
                                <table class="edit_table_css" width="90%">
                                    <tr>
                                        <th><?php echo $this->translate('购买数量');?></th>
                                        <th><?php echo $this->translate('单价');?></th>
                                    </tr>
                                    <?php foreach ($this->goodsWholesaleList as $wholesaleValue) { ?>
                                        <tr>
                                            <td style="text-align: center;"><?php echo $wholesaleValue->getWholesaleStartNum() . ' ~ ' . $wholesaleValue->getWholesaleEndNum(); ?></td>
                                            <td style="text-align: center;"><?php echo $this->frontCurrency($wholesaleValue->getWholesalePrice()); ?></td>
                                        </tr>
                                    <?php } ?>
                                </table>
                            </div>
                        </div>
                    <?php } ?>
                    <form action="<?php echo $this->url('shop-cart', ['action'=>'add']); ?>" method="post" name="addGoodsCartForm" id="addGoodsCartForm">
                        <?php if ($this->goodsSpec) { ?>
                            <dd class="goods-info-head-colors clearfix">
                                <?php foreach ($this->goodsSpec as $goodsSpecValue) { ?>
                                    <span><?php echo $this->escapeHtml($goodsSpecValue['tagGroupName']); ?>：</span>
                                    <div class="clearfix goods_spec_<?php echo $goodsSpecValue['groupId']; ?> goods_spec_tag_item">
                                        <?php if(isset($goodsSpecValue['tagList']) && !empty($goodsSpecValue['tagList'])) { foreach ($goodsSpecValue['tagList'] as $specTagValue) { ?>
                                            <div class="colorli">
                                                <a id="spec_value_<?php echo $specTagValue['tagId']; ?>" <?php if($this->selectedSpecTagId && in_array($specTagValue['tagId'], $this->selectedSpecTagId)) echo 'class="coloractive"'; ?> href="javascript:;" onclick="selectGoodsSpec(<?php echo $specTagValue['tagId']; ?>, <?php echo $goodsSpecValue['groupId']; ?>);" style="cursor: pointer;"><?php echo $this->escapeHtml($specTagValue['tagName']); ?></a>
                                            </div>
                                        <?php } } ?>
                                    </div>
                                <?php } ?>
                                <input type="hidden" name="specTagIdCount" id="specTagIdCount" value="<?php echo count($this->goodsSpec); ?>">
                                <input type="hidden" name="specTagIdStr" id="specTagIdStr" value="<?php if($this->selectedSpecTagId) echo implode(',', $this->selectedSpecTagId); ?>">
                            </dd>
                        <?php } ?>

                        <dd id="goodsDetailBtnBox" class="goods-info-head-cart">
                            <div style="margin-bottom:8px;">
                                <?php echo $this->translate('我想买'); ?>：
                                <button class="btn btn-primary" id="add_down" style="cursor: pointer;height: 30px;line-height: 30px;" type="button">-</button>
                                <input type="text" style="width:30px;margin-bottom:2px;" name="buyNum" id="buyNum" value="<?php echo (max($this->goodsInfo['cartBuyMinNum'], 1)); ?>" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
                                <button class="btn btn-primary" id="add_up" style="cursor: pointer; pointer;height: 30px;line-height: 30px;" type="button">+</button>
                                <label for="buy_goods_num" generated="true" class="error" style="display: inline-block;"></label>
                            </div>
                            <input type="hidden" id="goodsId" name="goodsId" value="<?php echo $this->goodsInfo[0]->getGoodsId(); ?>" />
                            <?php if (isset($this->showData['buyButtonHtml'])) echo $this->showData['buyButtonHtml']; ?>
                            <?php if (!isset($this->showData['noShowCartButton'])) { ?>
                                <button type="button" class="btn btn-primary goods-add-cart-btn" id="add_cart_submit">
                                    <i class="iconfont "></i><?php echo $this->translate('加入购物车'); ?></button>
                            <?php } ?>
                            <button type="button" title="<?php echo $this->translate('收藏商品'); ?>" id="button-add-to-wishlist" class="btn <?php echo $this->shopHelper()->getGoodsFavoritesStatus($this->goodsInfo[0]->getGoodsId()) ? 'btn-primary' : 'btn-dake'; ?> goods-collect-btn">
                                <i class="iconfont"></i>
                            </button>
                            <?php if($this->shopHelper()->shop('goods_qr_code', 'qr_code') == 1) { ?>
                                &nbsp;<img alt="<?php echo $this->translate('手机扫描后，在手机中访问该商品'); ?>" title="<?php echo $this->translate('手机扫描后，在手机中访问该商品'); ?>" width="60px" src="<?php echo $this->shopHelper()->baseImagePath($this->shopHelper()->helperCreateQrCodeFile($this->url('shop-goods', ['id' => $this->goodsInfo[0]->getGoodsId()], ['force_canonical' => true]), 'goods', $this->goodsInfo[0]->getGoodsId())); ?>">
                            <?php } ?>

                            <?php if (isset($this->showData['distributionStr'])) { ?>
                                <script type="text/javascript" src="<?php echo $this->basePath('js/plugins/clipboard/clipboard.min.js')?>"></script>
                                <button type="button" onclick="copyDistributionUrl();" class="btn btn-primary btn-copy-distributionUrl"  data-clipboard-text="<?php echo $this->url('shop-goods', ['id' => $this->goodsInfo[0]->getGoodsId()], ['query' => ['dStr' => $this->showData['distributionStr']], 'force_canonical' => true]); ?>" style="width: 130px;"><i class="fa fa-share-alt"></i> <?php echo $this->translate('复制分享链接'); ?></button>
                                <script type="text/javascript">
                                    function copyDistributionUrl() {
                                        let clipboard = new ClipboardJS('.btn-copy-distributionUrl');
                                        clipboard.on('success', function (e) {
                                            layer.msg('<?php echo $this->translate('复制完成！'); ?>');
                                            clipboard.destroy();
                                        });
                                        clipboard.on('error', function (e) {
                                            layer.msg('<?php echo $this->translate('复制不成功，请您手动进行复制！'); ?>');
                                        });
                                    }
                                </script>
                            <?php } ?>
                        </dd>
                    </form>
                    <dd style="margin-top: 3px;">
                        <?php echo $this->translate('最近'); ?><span id="ajax_order_count"><?php echo intval($this->goodsInfo[0]->getVirtualSales() + $this->goodsInfo['goodsSalesNum']); ?></span><?php echo $this->translate('人已经购买'); ?>
                    </dd>
                </dl>
            </dt>
        </dl>
    </div>
</div>
<script type="text/javascript">
    $("#add_up").click(function() {
        let buyNum = parseInt($('#buyNum').val());
        let maxNum = <?php echo $this->goodsInfo['cartBuyMaxNum']; ?>;
        if(buyNum >= maxNum && maxNum > 0) {
            showMessage('<?php echo $this->translate('每次购买最多数量为'); ?> '+maxNum);
            return false;
        }
        $('#buyNum').val( parseInt($('#buyNum').val()) + 1 );
    });
    $("#add_down").click(function() {
        let buyNum = parseInt($('#buyNum').val());
        let minNum = <?php echo $this->goodsInfo['cartBuyMinNum']; ?>;
        if(buyNum <= minNum && minNum > 0) {
            showMessage('<?php echo $this->translate('每次购买最少数量为'); ?> '+minNum);
            return false;
        }
        if( parseInt($('#buyNum').val())  > 1 ) {
            $('#buyNum').val( parseInt($('#buyNum').val()) - 1 );
        }
    });

    $('#buyNum').blur(function() {
        if ( $(this).val() < 1 ) $(this).val(1);
    });
</script>
